﻿#region

using System.Collections.Generic;
using System.IO;
using System.Text;
using Newtonsoft.Json;
using JsonSerializer = CuongHanh.Context.JsonSerializer;

#endregion

namespace CuongHanh.Service
{
    public class BaseService
    {
        protected static string FormatResult<T>(int total,
                IEnumerable<T> list)
        {
            StringBuilder stringBuilder = new StringBuilder();
            JsonWriter writer = new JsonTextWriter(new StringWriter(stringBuilder));
            writer.Formatting = Formatting.None;
            writer.WriteStartObject();
            writer.WritePropertyName("total");
            writer.WriteValue(total);
            writer.WritePropertyName("data");
            writer.WriteValue(JsonSerializer.SerializeList(list));
            writer.WriteEndObject();
            return stringBuilder.ToString();
        }
    }
}
